package com.develop.skwen.yourelectricmall.activity.view;

import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;

import com.develop.skwen.ourrules.view.BaseView;
import com.develop.skwen.yourelectricmall.R;
import com.develop.skwen.yourelectricmall.activity.adapter.MainFragmentAdapter;
import com.develop.skwen.yourelectricmall.activity.presenter.MainPresenter;
import com.develop.skwen.yourelectricmall.activity.view.vu.MainVu;

/**
 * Created by skwen
 * on 18-4-24
 */

public class MainView extends BaseView<MainPresenter> implements MainVu {

    private ViewPager mViewPager;
    private TabLayout mTabLayout;


    @Override
    protected int getLayoutRes() {
        return R.layout.activity_main;
    }

    @Override
    protected void initViews() {
        mViewPager = findViewById(R.id.viewPager);
        mTabLayout = findViewById(R.id.tabLayout);
    }

    @Override
    public void setAdapter(MainFragmentAdapter mainFragmentAdapter) {
        mViewPager.setAdapter(mainFragmentAdapter);
        mTabLayout.setupWithViewPager(mViewPager);
        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                getPresenter().onPageSelected(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        setTabLayout();
        mViewPager.setCurrentItem(0);
    }

    private void setTabLayout() {
        //指定Tab的位置
        TabLayout.Tab one = mTabLayout.getTabAt(0);
        TabLayout.Tab two = mTabLayout.getTabAt(1);
        TabLayout.Tab three = mTabLayout.getTabAt(2);
        TabLayout.Tab four = mTabLayout.getTabAt(3);
        // 设置Tab的图标
        one.setIcon(R.mipmap.icon_home);
        two.setIcon(R.mipmap.icon_category);
        three.setIcon(R.mipmap.icon_shop);
        four.setIcon(R.mipmap.icon_mine);
    }
}
